/**
 * LogService.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2014年7月17日
 */
package com.pshare.sys.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pshare.framework.mapper.BaseMapper;
import com.pshare.framework.service.BaseService;
import com.pshare.sys.bean.Log;
import com.pshare.sys.mapper.LogMapper;

/**
 * 操作日志业务层
 */
@Service
public class LogService extends BaseService<Long, Log> {
	
	private static final Integer OVER_TIME_DAYS = 14;

	@Autowired
	private LogMapper logMapper;
	
	@Override
	protected BaseMapper<Long, Log> getBaseMapper() {
		return logMapper;
	}
	
	public void record(Long userId, Integer clientType, Integer actionType, String method, String opContent) {
		Log log = new Log();
		log.setUserId(userId);
		log.setClientType(clientType);
		log.setActionType(actionType);
		log.setMethod(method);
		log.setOpContent(opContent);

		logMapper.add(log);
	}
	
	/**
	 * 清除过期日志
	 */
	public void clearOvertimeRecords() {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("diff", OVER_TIME_DAYS);
		logMapper.delete(params);
	}

}
